package com.wngbms;

import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixObservableCommand;
import lombok.extern.slf4j.Slf4j;
import rx.Observable;
import rx.Subscriber;
import rx.schedulers.Schedulers;

@Slf4j
public class CommandHelloWorldCmd extends HystrixObservableCommand<String> {

    protected CommandHelloWorldCmd() {
        // error 编译失败
//        HystrixCommandGroupKey expGrp = HystrixCommandGroupKey.Factory.asKey("ExpGrp");
//        super(expGrp);
        super(HystrixCommandGroupKey.Factory.asKey("expGrp"));
    }

    @Override
    protected Observable<String> construct() {
        Observable.OnSubscribe<String> subscribe = new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                log.info(" ----> do call");
                subscriber.onNext("hello");
                subscriber.onCompleted();
            }
        };

        Observable<String> observable = Observable.create(subscribe);
        Observable<String> observable1 = observable.subscribeOn(Schedulers.io());

        return observable1;
    }
}
